<script setup>
import {ref, watch} from 'vue'
import {generateNewStyle, writeNewStyle} from './index.js'

const color = ref('rgba(255, 69, 0, 0.68)')
const predefineColors = ref([
  '#ff4500',
  '#ff8c00',
  '#ffd700',
  '#90ee90',
  '#00ced1',
  '#1e90ff',
  '#c71585',
  'rgba(255, 69, 0, 0.68)',
  'rgb(255, 120, 0)',
  'hsv(51, 100, 98)',
  'hsva(120, 40, 94, 0.5)',
  'hsl(181, 100%, 37%)',
  'hsla(209, 100%, 56%, 0.73)',
  '#c7158577',
])
watch(color, async (newVal) => {
  const newStyleText = await generateNewStyle(newVal)
  writeNewStyle(newStyleText)
})

async function handleColorChange(value) {
  setTimeout(() => {
    color.value = value
  }, 1000)
}
</script>

<template>
  <div>
    <div style="display: flex">
      <div>
        <el-color-picker v-model="color" :predefine="predefineColors" show-alpha @active-change="handleColorChange"/>
      </div>
      <el-button type="primary">Primary</el-button>
    </div>
  </div>
</template>
